package Test;

import static org.junit.Assert.*;

import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import Modele.Case;
import Modele.Monde;
import Modele.Position;
import PathFinding.Map;
import PathFinding.Node;
import PathFinding.NodeList;

public class TestFindPath {

	Monde monde;
	
	
	@After
	public void tearDown() throws Exception {
		monde = null;
	}

	@Test
	public void test() {
		monde = new Monde(3,3);
		Case case00 = new Case(0, 0,null, 0,monde);
		monde.setCaseAtPosition(0, 0,case00);
		Case case01 = new Case(1, 0,null, 0,monde);
		monde.setCaseAtPosition(0, 1,case01);
		Case case02 = new Case(1, 0,null, 0,monde);
		monde.setCaseAtPosition(0, 1,case02);
		Case case10 = new Case(0, 0,null, 0,monde);
		monde.setCaseAtPosition(1,0 ,case10);
		Case case11 = new Case(0, 0,null, 0,monde);
		monde.setCaseAtPosition(1, 1,case11);
		Case case12 = new Case(0, 0,null, 0,monde);
		monde.setCaseAtPosition(1,2,case12);
		Case case20 = new Case(2, 0,null, 0,monde);
		monde.setCaseAtPosition(2,0,case20);
		Case case21 = new Case(0, 0,null, 0,monde);
		monde.setCaseAtPosition(2,1,case21);
		Case case22 = new Case(0, 0,null, 0,monde);
		monde.setCaseAtPosition(2,2,case22);
		Map<Node> myMap = new Map<Node>(monde.getHauteur(), monde.getLargeur(), new NodeList());
		for(int i=0;i<monde.getHauteur();i++)
			for(int j=0;j<monde.getLargeur();j++)
				myMap.setPenalty(i, j, monde.getCaseFromPosition(new Position(i,j)).getNiveauTerrain());
		
		String stringPath = "";
		List<Node> path = myMap.findPath(0,0,2,2);
		for (int i = 0; i < path.size(); i++) {
            stringPath += "(" + path.get(i).getxPosition() + ", " + path.get(i).getyPosition() + ") -> ";
        }
		assertEquals("(1, 0) -> (1, 1) -> (2, 1) -> (2, 2) -> " ,stringPath);
	}

}
